//
//  JQFXHLoanOneViewController.swift
//  Lishui_JieDianQianHua
//
//  Created by 卢小艳 on 2025/7/17.
//

import Foundation
import UIKit


class JQFXHLoanOneViewController: HJYJBaseViewController {
    
    var jqfxhLastssPara : [String: String] = [:]
    var jqfxhttLists: [JQFXHLoanListuuItemModel] = []

    
    var jqfxhParauuDic : [String: String] = [:]
    
    var jqfxhCerdiwwt : String = ""

    override func viewDidLoad() {
        super.viewDidLoad()
        title = "申请额度"
        self.view.backgroundColor = UIColor.jqfxhSmallViewBgbbGray
        self.jqfxhSetupxxSubviews()
        
        
    }
    
    init(para: [String: String]) {
        self.jqfxhLastssPara = para
        super.init(nibName: nil, bundle: nil)
    }
    
    @MainActor required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
   
    
    @objc func jqfxhNicezzBtnClick() {
        self.jqfxhYubbqiButton.isSelected = false
        self.jqfxhYubbqiButton.backgroundColor = UIColor.jqfxhEasyRedvvBg
        
        self.jqfxhNiceaaButton.isSelected = true
        self.jqfxhNiceaaButton.backgroundColor = UIColor.jqfxhThemexxRed

        jqfxhCerdiwwt = "1"
        self.jqfxhParauuDic["credit"] = jqfxhCerdiwwt
    }
    
    @objc func jqfxhSelectyyCity() {
        if JQFXHNetworkManager.shared.partnerId == 3 {
            let jqfxhPicker = JQFXHShengrAdressPickerViewController()
            jqfxhPicker.jqfxhAddresskkBlock = {[weak self] addressString, lastCode in
                guard let self else { return }
                self.jqfxhParauuDic["cityOfWork"] = addressString
                self.jqfxhParauuDic["cityOfWorkCode"] = String(lastCode)
                self.jqfxhAdressiiContent.text = addressString
            }
            self.navigationController?.present(jqfxhPicker, animated: true)
            
        }else if JQFXHNetworkManager.shared.partnerId == 6 {
            let jqfxhPicker = JQFXHMoliAdressPickerViewController()
            jqfxhPicker.jqfxhAddresskkBlock = {[weak self] addressString, lastCode in
                guard let self else { return }
                self.jqfxhParauuDic["current_district_id"] = String(lastCode)
                self.jqfxhAdressiiContent.text = addressString
            }
            self.navigationController?.present(jqfxhPicker, animated: true)
        }else {
            let jqfxhPicker = JQFXHAddressPickerViewController()
            jqfxhPicker.jqfxhAddresskkBlock = {[weak self] privince, city, area in
                guard let self else { return }
                self.jqfxhAdressiiContent.text = privince + city + area
                self.jqfxhParauuDic["work_city"] = city + area
            }
            self.navigationController?.present(jqfxhPicker, animated: true)
        }
        
    }
    
    @objc func jqfxhYubbqiButtonClick() {
        self.jqfxhNiceaaButton.isSelected = false
        self.jqfxhNiceaaButton.backgroundColor = UIColor.jqfxhEasyRedvvBg
        self.jqfxhYubbqiButton.isSelected = true
        self.jqfxhYubbqiButton.backgroundColor = UIColor.jqfxhThemexxRed
        jqfxhCerdiwwt = "2"
        self.jqfxhParauuDic["credit"] = jqfxhCerdiwwt

    }
    
    @objc func jqfxhNexteeBtnClick() {
        if let address = self.jqfxhAdressiiContent.text {
            if address.isEmpty || address == "请选择城市"{
                JQFXHHUD.jqfxhShowxxText("请填写地址信息")
                return
            }
        }
        if self.jqfxhCerdiwwt.count == 0 {
            JQFXHHUD.jqfxhShowxxText("请选择信用情况")
            return
        }
        
        let merged = jqfxhParauuDic.merging(jqfxhLastssPara) { (_, new) in new }
        if JQFXHNetworkManager.shared.partnerId == 6 {
            let loanvc = JQFXHMoliLoanSubmitxxViewController(para: merged)
            self.navigationController?.pushViewController(loanvc, animated: true)
        }else {
            let loanvc = JQFXHLoanSubmitmmViewController.init(para: merged)
            self.navigationController?.pushViewController(loanvc, animated: true)
        }
                
    }
    
    
    
    func jqfxhSetupxxSubviews() -> Void {
        self.view.addSubview(jqfxhAdressTitlekkLabel)
        jqfxhAdressTitlekkLabel.snp.makeConstraints { make in
            make.left.equalTo(self.view).offset(15)
            make.top.equalTo(self.view).offset(30)
        }
        
        self.view.addSubview(jqfxhAdressiiContentView)
        jqfxhAdressiiContentView.snp.makeConstraints { make in
            make.left.equalTo(self.view).offset(15)
            make.centerX.equalTo(self.view)
            make.top.equalTo(jqfxhAdressTitlekkLabel.snp.bottom).offset(10)
            make.height.equalTo(47)
        }
        
        jqfxhAdressiiContentView.addSubview(jqfxhAdressiiContentTitle)
        jqfxhAdressiiContentTitle.snp.makeConstraints { make in
            make.left.equalTo(jqfxhAdressiiContentView).offset(15)
            make.centerY.equalTo(jqfxhAdressiiContentView)
        }
        jqfxhAdressiiContentView.addSubview(jqfxhAdressiiContent)
        jqfxhAdressiiContent.snp.makeConstraints { make in
            make.right.equalTo(jqfxhAdressiiContentView).offset(-15)
            make.centerY.equalTo(jqfxhAdressiiContentView)

        }
        
        self.view.addSubview(jqfxhCredithhTitleLabel)
        jqfxhCredithhTitleLabel.snp.makeConstraints { make in
            make.left.equalTo(jqfxhAdressTitlekkLabel)
            make.top.equalTo(jqfxhAdressiiContentView.snp.bottom).offset(20)
        }
        
        self.view.addSubview(jqfxhCreditggBg)
        jqfxhCreditggBg.snp.makeConstraints { make in
            make.left.right.equalTo(jqfxhAdressiiContentView)
            make.top.equalTo(jqfxhCredithhTitleLabel.snp.bottom).offset(10)
            make.height.equalTo(100)
        }
        
        jqfxhCreditggBg.addSubview(jqfxhCreditffSubTitleLabel)
        jqfxhCreditffSubTitleLabel.snp.makeConstraints { make in
            make.left.equalTo(jqfxhCreditggBg).offset(10)
            make.top.equalTo(jqfxhCreditggBg).offset(15)
        }
        
        jqfxhCreditggBg.addSubview(jqfxhNiceaaButton)
        jqfxhNiceaaButton.snp.makeConstraints { make in
            make.left.equalTo(jqfxhCreditffSubTitleLabel)
            make.top.equalTo(jqfxhCreditffSubTitleLabel.snp.bottom).offset(10)
            make.height.equalTo(40)
            
        }
        
        jqfxhCreditggBg.addSubview(jqfxhYubbqiButton)
        jqfxhYubbqiButton.snp.makeConstraints { make in
            make.left.equalTo(jqfxhNiceaaButton.snp.right).offset(15)
            make.top.equalTo(jqfxhNiceaaButton)
            make.right.equalTo(jqfxhCreditggBg).offset(-10)
            make.height.equalTo(40)
            make.width.equalTo(jqfxhNiceaaButton)
        }
        
        self.view.addSubview(jqfxhNextccButton)
        jqfxhNextccButton.snp.makeConstraints { make in
            make.left.equalTo(self.view).offset(28)
            make.right.equalTo(self.view).offset(-28)
            make.top.equalTo(jqfxhCreditggBg.snp.bottom).offset(30)
            make.height.equalTo(42)
        }
        
        let ges = UITapGestureRecognizer(target: self, action: #selector(jqfxhSelectyyCity))
        jqfxhAdressiiContentView.addGestureRecognizer(ges)
        
        self.view.addSubview(jqfxhMoneyddCompanyLabel)
        jqfxhMoneyddCompanyLabel.snp.makeConstraints { make in
            make.centerX.equalTo(self.view)
            make.top.equalTo(jqfxhNextccButton.snp.bottom).offset(15)
        }
        
        
        
    }
    
    
    
    lazy var jqfxhAdressTitlekkLabel : UILabel = {
        let jqfxhAdressTitlekkLabel = UILabel()
        jqfxhAdressTitlekkLabel.font = UIFont.jqfxhMedium18
        jqfxhAdressTitlekkLabel.textColor = UIColor.black
        jqfxhAdressTitlekkLabel.text = "居住地址"
        return jqfxhAdressTitlekkLabel
    }()
    
   
    
    lazy var jqfxhAdressiiContentView : UIView = {
        let jqfxhAdressiiContentView = UIView()
        jqfxhAdressiiContentView.backgroundColor = UIColor.white
        jqfxhAdressiiContentView.layer.cornerRadius = 8
        jqfxhAdressiiContentView.layer.masksToBounds = true
        return jqfxhAdressiiContentView
    }()
    
    lazy var jqfxhAdressiiContentTitle : UILabel = {
        let jqfxhAdressiiContentTitle = UILabel()
        jqfxhAdressiiContentTitle.font = UIFont.jqfxhRegular16
        jqfxhAdressiiContentTitle.textColor = UIColor.black
        jqfxhAdressiiContentTitle.text = "居住城市"
        return jqfxhAdressiiContentTitle
    }()
    
    lazy var jqfxhAdressSubjjTitleLabel : UILabel = {
        let jqfxhAdressSubjjTitleLabel = UILabel()
        jqfxhAdressSubjjTitleLabel.font = UIFont.jqfxhRegular14
        jqfxhAdressSubjjTitleLabel.textColor = UIColor.black
        jqfxhAdressSubjjTitleLabel.text = "请选长期居住城市"
        return jqfxhAdressSubjjTitleLabel
    }()
    
    
    lazy var jqfxhAdressiiContent : UILabel = {
        let jqfxhAdressiiContent = UILabel()
        jqfxhAdressiiContent.font = UIFont.jqfxhRegular16
        jqfxhAdressiiContent.textColor = UIColor.lightGray
        jqfxhAdressiiContent.text = "选择城市>"
        return jqfxhAdressiiContent
    }()
    
    lazy var jqfxhCreditggBg : UIView = {
        let jqfxhCreditggBg = UIView()
        jqfxhCreditggBg.backgroundColor = UIColor.white
        jqfxhCreditggBg.layer.cornerRadius = 8
        jqfxhCreditggBg.layer.masksToBounds = true
        return jqfxhCreditggBg
    }()
    
    lazy var jqfxhCredithhTitleLabel : UILabel = {
        let jqfxhCredithhTitleLabel = UILabel()
        jqfxhCredithhTitleLabel.font = UIFont.jqfxhMedium18
        jqfxhCredithhTitleLabel.textColor = UIColor.black
        jqfxhCredithhTitleLabel.text = "逾期情况"
        return jqfxhCredithhTitleLabel
    }()
    
    
    
    lazy var jqfxhCreditffSubTitleLabel : UILabel = {
        let jqfxhCreditffSubTitleLabel = UILabel()
        jqfxhCreditffSubTitleLabel.font = UIFont.jqfxhRegular16
        jqfxhCreditffSubTitleLabel.textColor = UIColor.black
        jqfxhCreditffSubTitleLabel.text = "信用情况"
        return jqfxhCreditffSubTitleLabel
    }()
    
    lazy var jqfxhNiceaaButton: UIButton = {
        let jqfxhNiceaaButton = UIButton(type: .custom)
        jqfxhNiceaaButton.setTitle("信用良好", for: .normal)
        jqfxhNiceaaButton.backgroundColor = UIColor.jqfxhEasyRedvvBg
        jqfxhNiceaaButton.setTitleColor(.jqfxhThemexxRed, for: .normal)
        jqfxhNiceaaButton.setTitleColor(.white, for: .selected)
        jqfxhNiceaaButton.layer.cornerRadius = 4
        jqfxhNiceaaButton.titleLabel?.font = UIFont.jqfxhRegular14
        jqfxhNiceaaButton.addTarget(self, action: #selector(jqfxhNicezzBtnClick), for: .touchUpInside)
        return jqfxhNiceaaButton
    }()
    
   
    
    lazy var jqfxhNextccButton: UIButton = {
        let jqfxhNextccButton = UIButton(type: .custom)
        jqfxhNextccButton.setTitle("下一步", for: .normal)
        jqfxhNextccButton.backgroundColor = UIColor.jqfxhThemexxRed
        jqfxhNextccButton.setTitleColor(.white, for: .normal)
        jqfxhNextccButton.layer.cornerRadius = 8
        jqfxhNextccButton.addTarget(self, action: #selector(jqfxhNexteeBtnClick), for: .touchUpInside)
        return jqfxhNextccButton
    }()
    
    lazy var jqfxhYubbqiButton: UIButton = {
        let jqfxhYubbqiButton = UIButton(type: .custom)
        jqfxhYubbqiButton.setTitle("信用逾期", for: .normal)
        jqfxhYubbqiButton.backgroundColor = UIColor.jqfxhEasyRedvvBg
        jqfxhYubbqiButton.setTitleColor(.jqfxhThemexxRed, for: .normal)
        jqfxhYubbqiButton.setTitleColor(.white, for: .selected)
        jqfxhYubbqiButton.layer.cornerRadius = 4
        jqfxhYubbqiButton.titleLabel?.font = UIFont.jqfxhRegular14
        jqfxhYubbqiButton.addTarget(self, action: #selector(jqfxhYubbqiButtonClick), for: .touchUpInside)
        return jqfxhYubbqiButton
    }()
    
    
    lazy var jqfxhMoneyddCompanyLabel : UILabel = {
        let jqfxhMoneyddCompanyLabel = UILabel()
        jqfxhMoneyddCompanyLabel.text = JQFXHCompanyMessage.jqfxhZhongMoneyCompanyName
        jqfxhMoneyddCompanyLabel.font = UIFont.jqfxhMedium13
        jqfxhMoneyddCompanyLabel.textColor = UIColor.jqfxhTextLightaaGray
        return jqfxhMoneyddCompanyLabel
    }()
    
    
}
